<meta name="csrf-token" content="{{ csrf_token() }}">
<style type="text/css">

</style>
<section class="content">
    <div class="row"><div class="col-md-12"><div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">创建</h3>

                    <div class="box-tools">
                        <div class="btn-group pull-right" style="margin-right: 5px">
                            <a href="/admin/camp/setting" class="btn btn-sm btn-default" title="列表"><i class="fa fa-list"></i><span class="hidden-xs">&nbsp;列表</span></a>
                        </div>
                    </div>
                </div>

                    <div class="box-body">

                            <div class="control-group row">
                                <label for="type" class="col-sm-2  control-label" style="text-align:right">大营</label>

                                <div class="col-md-8">
                                    <select class="form-control" id="camp" name="camp">
                                        @foreach($camps as $v)
                                            <option value="{{$v->id}}">{{$v->name}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>

                        <div class="control-group row">
                            <label for="color" class="col-sm-2  control-label" style="text-align:right">配色</label>

                            <div class="col-md-8">
                                <select class="form-control" id="color" name="color">
                                    <option value="1">Wonder Museum</option>
                                    <option value="2">Fantastic Writing</option>
                                    <option value="3">Speak Great</option>
                                    <option value="4">the Broadway</option>
                                    <option value="5">Science Festival</option>
                                </select>
                            </div>
                        </div>

                            <div class="control-group row">
                                <label for="cover" class="col-sm-2  control-label" style="text-align:right">封面背景</label>

                                <div class="col-md-8">
                                    <input type="file" name="cover" id="cover" data-min-file-count="1" class="form-control"/>
                                </div>
                            </div>

                            <div class="control-group row">
                                <label for="background" class="col-sm-2  control-label" style="text-align:right">正文背景</label>

                                <div class="col-md-8">
                                    <input type="file" name="background" id="background" data-min-file-count="1" class="form-control"/>
                                </div>
                            </div>

                            <div class="control-group row" style="">
                                <label for="type" class="col-sm-2  control-label" style="text-align:right;margin-top:35px">项目</label>
                                <div class="col-md-8">
                                    <ul id="myTab" class="nav nav-pills" role="tablist" style="display:inline-block;margin-top:30px">
                                        <li><a href="#kaoqin" role="tab" data-toggle="tab">考勤</a></li>
                                        <li><a href="#jiaxiao" role="tab" data-toggle="tab">家校</a></li>
                                        <li><a href="#dictation" role="tab"  data-toggle="tab">听写</a></li>
                                        <li><a href="#test" role="tab" data-toggle="tab">测试</a></li>
                                        <li><a href="#zuoye" role="tab" data-toggle="tab">作业</a></li>
                                        <li><a href="#radar" role="tab" data-toggle="tab">雷达</a></li>
                                    </ul>
                                    <a class="btn btn-success" role="button" id="add" style="margin-left:20px;margin-bottom:30px"><i class="glyphicon glyphicon-plus"></i></a>
                                    <a class="btn btn-danger" role="button" id="minus" style="margin-bottom:30px"><i class="glyphicon glyphicon-minus"></i></a>
                                </div>
                            </div>


                            <hr style="border:1px solid"/>
                        <!-- 选项卡面板 -->
                        <div id="myTabContent" class="tab-content">
                            <form class="tab-pane form-group" id="kaoqin">
                                <div class="control-group row" style="text-align:right">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-md-2">
                                        <label class="control-label">启用</label>
                                        <input type="radio" name="kaoqin_status" value="on"/>
                                    </div>
                                    <div class="col-md-2">
                                        <label class="control-label">禁用</label>
                                        <input type="radio" name="kaoqin_status" value="off"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">周期</label>
                                    <div class="col-md-2">
                                        <label class="control-label">每天</label>
                                        <input type="radio" name="kaoqin_time" value="everyday"/>
                                    </div>
                                    <div class="col-md-6" style="text-align:left;">
                                        <label class="control-label">自定义</label>
                                        <input type="radio" name="kaoqin_time" value="custom"/>
                                        <input style="width: 110px;display:inline-block;margin-left:30px" type="text" id="kaoqin_time_input" class="myTime" value="" placeholder="时间">
                                        <a class="btn btn-success btn-sm timeSubmit" myType="kaoqin" id="kaoqin_time_submit"><i class="glyphicon glyphicon-ok"></i></a>
                                        <a class="btn btn-danger btn-sm timeMinus" myType="kaoqin" id="kaoqin_time_minus"><i class="glyphicon glyphicon-minus"></i></a>
                                    </div>
                                </div>
                                <div id="kaoqin_time_custom" class="control-group" style="">

                                </div>
                            </form>
                            <form class="tab-pane form-group" id="jiaxiao">
                                <div class="control-group row" style="text-align:right">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-md-2">
                                        <label class="control-label">启用</label>
                                        <input type="radio" name="jiaxiao_status" value="on"/>
                                    </div>
                                    <div class="col-md-2">
                                        <label class="control-label">禁用</label>
                                        <input type="radio" name="jiaxiao_status" value="off"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">总分</label>
                                    <div class="col-md-3">
                                        <input type="text" id="jiaxiao_score" name="jiaxiao_total_score" class="score" myType="jiaxiao"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">周期</label>
                                    <div class="col-md-2">
                                        <label class="control-label">每天</label>
                                        <input type="radio" name="jiaxiao_time" value="everyday"/>
                                    </div>
                                    <div class="col-md-6" style="text-align:left;">
                                        <label class="control-label">自定义</label>
                                        <input type="radio" name="jiaxiao_time" value="custom"/>
                                        <input style="width: 110px;display:inline-block;margin-left:30px" type="text" id="jiaxiao_time_input" class="myTime" value="" placeholder="时间">
                                        <a class="btn btn-success btn-sm timeSubmit" myType="jiaxiao" id="jiaxiao_time_submit"><i class="glyphicon glyphicon-ok"></i></a>
                                        <a class="btn btn-danger btn-sm timeMinus" myType="jiaxiao" id="jiaxiao_time_minus"><i class="glyphicon glyphicon-minus"></i></a>
                                    </div>
                                </div>
                                <div id="jiaxiao_time_custom" class="control-group" style="">

                                </div>
                            </form>
                            <form class="tab-pane form-group" id="dictation">
                                <div class="control-group row" style="text-align:right">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-md-2">
                                        <label class="control-label">启用</label>
                                        <input type="radio" name="dictation_status" value="on"/>
                                    </div>
                                    <div class="col-md-2">
                                        <label class="control-label">禁用</label>
                                        <input type="radio" name="dictation_status" value="off"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">总分</label>
                                    <div class="col-md-3">
                                        <input type="text" id="dictation_score" name="dictation_total_score" class="score" myType="dictation"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">周期</label>
                                    <div class="col-md-2">
                                        <label class="control-label">每天</label>
                                        <input type="radio" name="dictation_time" value="everyday"/>
                                    </div>
                                    <div class="col-md-6" style="text-align:left;">
                                        <label class="control-label">自定义</label>
                                        <input type="radio" name="dictation_time" value="custom"/>
                                        <input style="width: 110px;display:inline-block;margin-left:30px" type="text" id="dictation_time_input" class="myTime" value="" placeholder="时间">
                                        <a class="btn btn-success btn-sm timeSubmit" myType="dictation" id="dictation_time_submit"><i class="glyphicon glyphicon-ok"></i></a>
                                        <a class="btn btn-danger btn-sm timeMinus" myType="dictation" id="dictation_time_minus"><i class="glyphicon glyphicon-minus"></i></a>
                                    </div>
                                </div>
                                <div id="dictation_time_custom" class="control-group" style="">

                                </div>
                            </form>
                            <form class="tab-pane form-group" id="test">
                                <div class="control-group row" style="text-align:right">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-md-2">
                                        <label class="control-label">启用</label>
                                        <input type="radio" name="test_status" value="on"/>
                                    </div>
                                    <div class="col-md-2">
                                        <label class="control-label">禁用</label>
                                        <input type="radio" name="test_status" value="off"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">总分</label>
                                    <div class="col-md-3">
                                        <input type="text" id="test_score" name="test_total_score" class="score" myType="test"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">周期</label>
                                    <div class="col-md-2">
                                        <label class="control-label">每天</label>
                                        <input type="radio" name="test_time" value="everyday"/>
                                    </div>
                                    <div class="col-md-6" style="text-align:left;">
                                        <label class="control-label">自定义</label>
                                        <input type="radio" name="test_time" value="custom"/>
                                        <input style="width: 110px;display:inline-block;margin-left:30px" type="text" id="test_time_input" class="myTime" value="" placeholder="时间">
                                        <a class="btn btn-success btn-sm timeSubmit" myType="test" id="test_time_submit"><i class="glyphicon glyphicon-ok"></i></a>
                                        <a class="btn btn-danger btn-sm timeMinus" myType="test" id="test_time_minus"><i class="glyphicon glyphicon-minus"></i></a>
                                    </div>
                                </div>
                                <div id="test_time_custom" class="control-group" style="">

                                </div>
                            </form>
                            <form class="tab-pane form-group" id="zuoye">
                                <div class="control-group row" style="text-align:right">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-md-2">
                                        <label class="control-label">启用</label>
                                        <input type="radio" name="zuoye_status" value="on"/>
                                    </div>
                                    <div class="col-md-2">
                                        <label class="control-label">禁用</label>
                                        <input type="radio" name="zuoye_status" value="off"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">总分</label>
                                    <div class="col-md-3">
                                        <input type="text" id="zuoye_score" name="zuoye_total_score" class="score" myType="zuoye"/>
                                    </div>
                                </div>
                                <div class="control-group row" style="text-align:right;margin-top:30px">
                                    <label class="col-sm-2 control-label">周期</label>
                                    <div class="col-md-2">
                                        <label class="control-label">每天</label>
                                        <input type="radio" name="zuoye_time" value="everyday"/>
                                    </div>
                                    <div class="col-md-6" style="text-align:left;">
                                        <label class="control-label">自定义</label>
                                        <input type="radio" name="zuoye_time" value="custom"/>
                                        <input style="width: 110px;display:inline-block;margin-left:30px" type="text" id="zuoye_time_input" class="myTime" value="" placeholder="时间">
                                        <a class="btn btn-success btn-sm timeSubmit" myType="zuoye" id="zuoye_time_submit"><i class="glyphicon glyphicon-ok"></i></a>
                                        <a class="btn btn-danger btn-sm timeMinus" myType="zuoye" id="zuoye_time_minus"><i class="glyphicon glyphicon-minus"></i></a>
                                    </div>
                                </div>
                                <div id="zuoye_time_custom" class="control-group" style="">

                                </div>
                            </form>
                            <form class="tab-pane form-group" id="radar">
                                <div class="control-group row" style="text-align:right">
                                    <label class="col-sm-2 control-label">状态</label>
                                    <div class="col-md-2">
                                        <label class="control-label">启用</label>
                                        <input type="radio" name="radar_status" value="on"/>
                                    </div>
                                    <div class="col-md-2">
                                        <label class="control-label">禁用</label>
                                        <input type="radio" name="radar_status" value="off"/>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>

                    <div class="box-footer">

                        <div class="col-md-2">
                        </div>

                        <div class="col-md-8">

                            <div class="btn-group pull-right">
                                <button id="save" class="btn btn-primary">提交</button>
                            </div>

                        </div>
                    </div>
            </div>

        </div></div>
</section>


<div class="modal fade" id="addModal" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <label class="control-label">自定义项目添加</label>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" id="remove"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">

                <form class="form-horizontal">
                    <fieldset>
                        <div class="control-group">
                            <!-- Select Basic -->
                            <label class="control-label">标识</label>
                            <label style="color:red">标识是编程需要，请只使用英文、数字和下划线。举例：point、po1nt、student_point</label>
                            <div class="controls">
                                <input class="form-control" type="text" id="Add_tag" title="请只使用英文、数字和下划线"/>
                            </div>
                        </div>

                        <div class="control-group">
                            <!-- Select Basic -->
                            <label class="control-label">名称</label>
                            <label style="color:red">举例：积分</label>
                            <div class="controls">
                                <input class="form-control" type="text" id="Add_name"/>
                            </div>
                        </div>
                    </fieldset>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" id="Addbtn_close" class="btn btn-default"  data-dismiss="modal">关闭</button>
                {{--<button type="button" id="btn_clear" class="btn btn-warning">清空</button>--}}
                <button type="button" id="Addbtn_submit" class="btn btn-primary">保存</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade" id="statusModal" role="dialog" aria-labelledby="myModalLabel" data-backdrop="static">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <label class="control-label">添加状态</label>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" id="statusremove"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">

                <form class="form-horizontal">
                    <fieldset>
                        <div class="control-group">
                            <!-- Select Basic -->
                            <label class="control-label">状态名称</label>
                            <div class="controls">
                                <input class="form-control" type="text" id="status_name"/>
                            </div>
                        </div>
                    </fieldset>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" id="status_close" class="btn btn-default"  data-dismiss="modal">关闭</button>
                <button type="button" id="status_submit" class="btn btn-primary">保存</button>
            </div>
            <input type="text" style="display:none" id="status_display">
        </div>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        $('#camp').select2();
        $('.myTime').each(function(){
            $(this).datetimepicker({format:'YYYY-MM-DD'});
        });

        $('#cover').fileinput({
            language: 'zh', //设置语言
            allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
            maxFileCount: 1,
            enctype: 'multipart/form-data',
            showUpload:false,
            removeLabel:"清空",
            browseLabel: "选择图片",
            browseClass: "btn btn-primary", //按钮样式
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
        });
        $('#background').fileinput({
            language: 'zh', //设置语言
            allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
            maxFileCount: 1,
            enctype: 'multipart/form-data',
            showUpload:false,
            removeLabel:"清空",
            browseLabel: "选择图片",
            browseClass: "btn btn-primary", //按钮样式
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
        });
    });


    $('#add').on('click',function(){
        $('#addModal').modal();
    });

    $('#Addbtn_close').on('click',function(){
        $('#addModal').modal('hide');
    });

    $('#Addbtn_submit').on('click',function(){
        if($('#Add_tag').val() == ''){
            alert('请填写标识！');
            return;
        }
        if($('#Add_name').val() == ''){
            alert('请填写名称！');
            return;
        }

        var regExp = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
        if(regExp.test($('#Add_tag').val()) == false){
            alert('标识填写不规范，请重新填写！');
            return;
        }

        var html = '<li class="Other"><a href="#'+$('#Add_tag').val()+'" role="tab" data-toggle="tab">'+$('#Add_name').val()+'</a></li>';
        $('#myTab').append(html);

        html = '<form class="tab-pane form-group Other" id="sign">\n' +
            '    <div class="control-group row" style="text-align:right">\n' +
            '        <label class="col-sm-2 control-label">状态</label>\n' +
            '        <div class="col-md-2">\n' +
            '            <label class="control-label">启用</label>\n' +
            '            <input type="radio" name="sign_status" value="on"/>\n' +
            '        </div>\n' +
            '        <div class="col-md-2">\n' +
            '            <label class="control-label">禁用</label>\n' +
            '            <input type="radio" name="sign_status" value="off"/>\n' +
            '        </div>\n' +
            '    </div>\n' +
            '    <div class="control-group row" style="text-align:right;margin-top:30px">\n' +
            '        <label class="col-sm-2 control-label">分数</label>\n' +
            '        <div class="col-md-2">\n' +
            '            <label class="control-label">启用</label>\n' +
            '            <input type="radio" name="sign_score" value="on"/>\n' +
            '        </div>\n' +
            '        <div class="col-md-3">\n' +
            '            <label class="control-label">总分</label>\n' +
            '            <input type="text" id="sign_score" name="sign_total_score" class="score" myType="sign"/>\n' +
            '        </div>\n' +
            '    </div>\n' +
            '    <div class="control-group row" style="text-align:right;margin-top:30px">\n' +
            '        <label class="col-sm-2 control-label">评分状态</label>\n' +
            '        <div class="col-md-2">\n' +
            '            <label class="control-label">启用</label>\n' +
            '            <input type="radio" name="sign_score_status" value="on"/>\n' +
            '        </div>\n' +
            '        <div class="col-md-6" style="text-align:left;">\n' +
            '            <label class="control-label">自定义</label>\n' +
            '            <a class="btn btn-success btn-sm statusSubmit" style="cursor:pointer" myType="sign" id="sign_status_submit"><i class="glyphicon glyphicon-plus"></i></a>\n' +
            '            <a class="btn btn-danger btn-sm statusMinus" myType="sign" id="sign_status_minus"><i class="glyphicon glyphicon-minus"></i></a>\n' +
            '        </div>\n' +
            '    </div>\n' +
            '    <div id="sign_status_custom" class="control-group" style="">\n' +
            '\n' +
            '    </div>\n' +
            '    <div class="control-group row" style="text-align:right;margin-top:30px">\n' +
            '        <label class="col-sm-2 control-label">周期</label>\n' +
            '        <div class="col-md-2">\n' +
            '            <label class="control-label">每天</label>\n' +
            '            <input type="radio" name="sign_time" value="everyday"/>\n' +
            '        </div>\n' +
            '        <div class="col-md-6" style="text-align:left;">\n' +
            '            <label class="control-label">自定义</label>\n' +
            '            <input type="radio" name="sign_time" value="custom"/>\n' +
            '            <input style="width: 110px;display:inline-block;margin-left:30px" type="text" id="sign_time_input" class="myTime" value="" placeholder="时间">\n' +
            '            <a class="btn btn-success btn-sm timeSubmit" myType="sign" id="sign_time_submit"><i class="glyphicon glyphicon-ok"></i></a>\n' +
            '            <a class="btn btn-danger btn-sm timeMinus" myType="sign" id="sign_time_minus"><i class="glyphicon glyphicon-minus"></i></a>\n' +
            '        </div>\n' +
            '    </div>\n' +
            '    <div id="sign_time_custom" class="control-group" style="">\n' +
            '\n' +
            '    </div>\n' +
            '</form>';

        html = html.replace(new RegExp(/sign/g),$('#Add_tag').val());
        $('#myTabContent').append(html);
        $('#'+$('#Add_tag').val()+'_time_input').datetimepicker({format:'YYYY-MM-DD'});
        $('#Add_tag').val('');
        $('#Add_name').val('');

        $('#Addbtn_close').click();
    });

    $('#minus').on('click',function(){
        $('#myTab .Other').last().remove();
        $('#myTabContent .Other').last().remove();
    });

    $('body').on('click','.timeSubmit',function(){
        var type = $(this).attr('myType');
        var name = type+'_time';

        if($("input[type='radio'][name="+name+"]:checked").val() != 'custom'){
            alert('请勾选自定义选项！');
            return;
        }
        if($('#'+type+'_time_input').val() == ''){
            return;
        }
        var i = $('#'+type+'_time_custom').children().length + 1;
        var html = '<div style="margin-left:28%">第'+i+'次——'+$('#'+type+'_time_input').val()+'</div>';
        $('#'+type+'_time_custom').append(html);

        $('#'+type+'_time_input').val('');
    });

    $('body').on('click','.timeMinus',function(){
        var type = $(this).attr('myType');
        var name = type+'_time_custom';


        $('#'+name).children(':last').remove();
    });

    $('.score').on('keyup',function(){
        var regExp = /^([1-9]\d?|100)$/;
        if(regExp.test($(this).val()) == false){
            $(this).val('');
            return;
        }
    });

    $('body').on('click','.statusSubmit',function(){
        var type = $(this).attr('myType');
        var name = type+'_score_status';
        if($("input[type='radio'][name="+name+"]:checked").val() != 'on'){
            alert('请勾选启用选项！');
            return;
        }

        $('#statusModal').modal();

        $('#status_display').val($(this).attr('myType'));
    });

    $('body').on('click','.statusMinus',function(){
        var type = $(this).attr('myType');
        var name = type+'_status_custom';


        $('#'+name).children(':last').remove();
    });

    $('#status_submit').on('click',function(){
        var name = $('#status_name').val();
        var type = $('#status_display').val();
        var length = $('#'+type+'_status_custom').children().length;
        var i = length + 1;

        var html = '<div style="margin-left:28%">'+i+'——'+name+'</div>';
        $('#'+type+'_status_custom').append(html);

        $('#status_name').val('');
        $('#status_close').click();
    });

    $('#status_close').on('click',function(){
        $('#statusModal').modal('hide');
    });


    $('#save').on('click',function(){
        var list = $('#myTab').children('li');

        var request = {};

        var StatusOn = 0;
        request['camp'] = $('#camp').val();
        request['color'] = $('#color').val();
        for(x in list){
            var key = $(list[x].childNodes).attr('href');
            key = String(key);
            key = key.replace('#','');
            if(typeof(key) != 'undefined' && key != 'undefined'){
                request[key] = {};
                request[key].name = $(list[x].childNodes).text();
                request[key].data = $('#'+key).serializeObject();
                var k = key+'_status';
                if(request[key].data[k] == 'on'){
                    StatusOn = 1;
                }

                var c_list = $('#'+key+'_status_custom').children('div');
                if(c_list.length != 0){
                    request[key].status = {};
                    var arr = {};
                    for(i=0;i<c_list.length;i++){
                        arr[i] = $(c_list[i]).text();
                    }
                    request[key].status = JSON.stringify(arr);
                }

                var c_list = $('#'+key+'_time_custom').children('div');
                if(c_list.length != 0){
                    request[key].time = {};
                    var arr = {};
                    for(i=0;i<c_list.length;i++){
                        arr[i] = $(c_list[i]).text();
                    }
                    request[key].time = JSON.stringify(arr);
                }
            }
        }
        if(StatusOn == 0){
            alert('配置失败，必须启用至少一项，请检查！');
            return;
        }
        $.ajaxSetup({headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}});

/*        $.post('/admin/camp/setting/save',request,function(e){
            if(e.status > 0){
                alert(e.message);
                window.location.href = "/admin/camp/setting";
            }else{
                alert(e.message);
            }
        });*/

        var formData = new FormData();
        formData.append('cover',document.getElementById("cover").files[0]);
        formData.append('background',document.getElementById("background").files[0]);
        formData.append('request',JSON.stringify(request));
        $.ajax({
            url:"/admin/camp/setting/save",
            type:"POST",
            data:formData,
//            dataType:"JSON",

            cache:false,         //不设置缓存
            processData: false,  // 不处理数据
            contentType: false,   // 不设置内容类型
            async:false,

            success:function(aj){
                alert('操作成功');
                window.location.href = "/admin/camp/setting";
            },
            error:function(aj){
                alert("ajax产生错误"+aj);
            }
        });

    });

    $.fn.serializeObject = function() {
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [ o[this.name] ];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }


</script>